/* 封装和文章相关的请求 */
import axios from '@/utils/request'

// 获取文章列表
export function getArticleList (params = {}) {
  return axios({
    method: 'get',
    url: '/mp/v1_0/articles',
    params
  })
}

// 获取频道列表
export function getChannelList () {
  return axios({
    method: 'get',
    url: '/mp/v1_0/channels'
  })
}

export function delArticle (id) {
  return axios({
    method: 'delete',
    url: `/mp/v1_0/articles/${id}`
  })
}

// 发表文章
export function addArticle (data) {
  return axios({
    method: 'POST',
    url: '/mp/v1_0/articles',
    data
  })
}

export function getArticle (id) {
  return axios({
    url: '/mp/v1_0/articles/' + id
  })
}

export function updateArticle (id, data) {
  return axios({
    method: 'put',
    url: '/mp/v1_0/articles/' + id,
    data
  })
}

// 修改文章评论状态
export function updateCommentStatus (article_id, allow_comment) {
  return axios({
    method: 'PUT',
    url: '/mp/v1_0/comments/status',
    params: {
      article_id
    },
    data: {
      allow_comment
    }
  })
}
